package com.jlu.yygh.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jlu.yygh.common.result.Result;
import com.jlu.yygh.common.utils.AuthContextHolder;
import com.jlu.yygh.model.user.UserInfo;
import com.jlu.yygh.service.UserInfoService;
import com.jlu.yygh.vo.user.LoginVo;
import com.jlu.yygh.vo.user.UserAuthVo;
import com.jlu.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/user")
@Api(tags = "会员接口管理")
public class UserInfoApiController {

  @Autowired
  private UserInfoService userInfoService;

  @ApiOperation(value = "会员登录")
  @PostMapping("login")
  public Result login(@RequestBody LoginVo loginVo, HttpServletRequest request){

    System.out.println(request.getHeader("name"));
    Map<String,Object> map = userInfoService.login(loginVo);

    return Result.ok(map);
  }

  //用户认证接口
  @PostMapping("auth/userAuth")
  public Result userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request) {
    //传递两个参数，第一个参数用户id，第二个参数认证数据vo对象
    userInfoService.userAuth(AuthContextHolder.getUserId(request),userAuthVo);
    return Result.ok();
  }

  //获取用户id信息接口
  @GetMapping("auth/getUserInfo")
  public Result getUserInfo(HttpServletRequest request) {
    Long userId = AuthContextHolder.getUserId(request);
    UserInfo userInfo = userInfoService.getById(userId);
    return Result.ok(userInfo);
  }
}
